//
//  LGAddMedicinLineView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/16.
//

#import "LGAddMedicinHeadView.h"

@interface LGAddMedicinHeadView()
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UILabel *unitLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , copy)NSString *key;

@end

@implementation LGAddMedicinHeadView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.key = LGNSString(dataDic[@"key"]);
    self.titleLabel.text = LGNSString(dataDic[@"title"]);
    self.iconView.image = [UIImage imageNamed:[NSString stringWithFormat:@"用药管理-%@",dataDic[@"title"]]];
    self.tipView.hidden = [dataDic[@"showTip"] isEqualToString:@"Y"]?NO:YES;
    self.lineView.hidden = [dataDic[@"showLine"] isEqualToString:@"Y"]?NO:YES;
}

-(void)setResultDic:(NSDictionary *)resultDic{
    _resultDic = resultDic;
    if([resultDic isKindOfClass:[NSDictionary class]] && resultDic.allKeys.count>0 && self.key.length>0){
        NSString *content = LGNSString(resultDic[self.key]);
        NSString *colorName = (content.length>0)?@"#666666":@"#999999";
        self.contentLabel.font = (content.length>0)?LGFont(16):LGFont(15);
        self.contentLabel.textColor = [UIColor colorWithString:colorName];
        self.contentLabel.text = (content.length>0)?content:@"请选择";
    }
}

-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView addSubview:self.unitLabel];
    [self.baseView addSubview:self.tipView];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.actionBtn];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(viewPix(8));
        make.left.equalTo(self).offset(viewPix(16));
        make.right.equalTo(self).offset(-viewPix(16));
        make.height.equalTo(@(viewPix(54)));
    }];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(20));
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(6));
        make.width.equalTo(@(viewPix(80)));
        make.centerY.equalTo(self.iconView);
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(viewPix(10));
        make.right.equalTo(self.unitLabel.mas_left);
        make.centerY.equalTo(self.iconView);
    }];
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.tipView.mas_left);
        make.centerY.equalTo(self.contentLabel).offset(viewPix(2));
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.width.height.equalTo(@(viewPix(12)));
        make.centerY.equalTo(self.iconView);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_bottom).offset(viewPix(12));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.left.equalTo(self.iconView);
        make.height.equalTo(@(0.5));
    }];
    [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self);
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(15) textAlignment:NSTextAlignmentRight lines:2];
    }
    return _contentLabel;
}

-(UILabel *)unitLabel{
    if(!_unitLabel){
        _unitLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _unitLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}

-(UIButton *)actionBtn{
    if(!_actionBtn){
        _actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _actionBtn;
}

@end
